home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / net_src.arc / lapbtime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-08  |  3.1 KB  |  142 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "ax25.h"
  5. #include "timer.h"
  6. #include "netuser.h"
  7. #include "session.h"
  8. #include "ftp.h"
  9. #include "telnet.h"
  10. #include "iface.h"
  11. #include "finger.h"
  12. #include "lapb.h"
  13.  
  14. /* Called whenever timer T1 expires */
  15. void
  16. recover(n)
  17. int *n;
  18. {
  19.     register struct ax25_cb *axp;
  20.     void lapbstate();
  21.  
  22.     axp = (struct ax25_cb *)n;
  23.  
  24.     switch(axp->state){
  25.     case SETUP:
  26.         if(axp->n2 != 0 && axp->retries == axp->n2){
  27.             free_q(&axp->txq);
  28.             lapbstate(axp,DISCONNECTED);
  29.         } else {
  30.             axp->retries++;
  31.             sendctl(axp,COMMAND,SABM|PF);
  32.             start_timer(&axp->t1);
  33.         }
  34.         break;
  35.     case DISCPENDING:
  36.         if(axp->n2 != 0 && axp->retries == axp->n2){
  37.             lapbstate(axp,DISCONNECTED);
  38.         } else {
  39.             axp->retries++;
  40.             sendctl(axp,COMMAND,DISC|PF);
  41.             start_timer(&axp->t1);
  42.         }
  43.         break;
  44.     case CONNECTED:
  45.         axp->retries = 0;
  46.     case RECOVERY:    /* note fall-thru */
  47.         if(axp->n2 != 0 && axp->retries == axp->n2){
  48.             /* Give up */
  49.             sendctl(axp,RESPONSE,DM|PF);
  50.             free_q(&axp->txq);
  51.             lapbstate(axp,DISCONNECTED);
  52.         } else {
  53.             /* Transmit poll */
  54.             tx_enq(axp);
  55.             axp->retries++;
  56.             lapbstate(axp,RECOVERY);
  57.         }
  58.         break;
  59.     case FRAMEREJECT:
  60.         if(axp->n2 != 0 && axp->retries == axp->n2){
  61.             sendctl(axp,RESPONSE,DM|PF);
  62.             free_q(&axp->txq);
  63.             lapbstate(axp,DISCONNECTED);
  64.         } else {
  65.             frmr(axp,0,0);    /* Retransmit last FRMR */
  66.             start_timer(&axp->t1);
  67.             axp->retries++;
  68.         }
  69.         break;
  70.     }
  71.     /* Empty the trash */
  72.     if(axp->state == DISCONNECTED)
  73.         del_ax25(axp);
  74. }
  75.  
  76. /* T2 has expired, we can't delay an acknowledgement any further */
  77. void
  78. send_ack(n)
  79. int *n;
  80. {
  81.     char control;
  82.     register struct ax25_cb *axp;
  83.  
  84.     axp = (struct ax25_cb *)n;
  85.     switch(axp->state){
  86.     case CONNECTED:
  87.     case RECOVERY:
  88.         control = len_mbuf(axp->rxq) > axp->window ? RNR : RR;
  89.         sendctl(axp,RESPONSE,control);
  90.         axp->response = 0;
  91.         break;
  92.     }
  93. }
  94.  
  95. /* Send a poll (S-frame command with the poll bit set) */
  96. void
  97. pollthem(n)
  98. int *n;
  99. {
  100.     register struct ax25_cb *axp;
  101.  
  102.     axp = (struct ax25_cb *)n;
  103.     if(axp->proto == V1)
  104.         return;    /* Not supported in the old protocol */
  105.     switch(axp->state){
  106.     case CONNECTED:
  107.         axp->retries = 0;
  108.         tx_enq(axp);
  109.         lapbstate(axp,RECOVERY);
  110.         break;
  111.     }
  112. }
  113. /* Transmit query */
  114. tx_enq(axp)
  115. register struct ax25_cb *axp;
  116. {
  117.     char ctl;
  118.     struct mbuf *bp;
  119.  
  120.     /* I believe that retransmitting the oldest unacked
  121.      * I-frame tends to give better performance than polling,
  122.      * as long as the frame isn't too "large", because
  123.      * chances are that the I frame got lost anyway.
  124.      * This is an option in LAPB, but not in the official AX.25.
  125.      */
  126.     if(axp->txq != NULLBUF && len_mbuf(axp->txq) < axp->pthresh
  127.      && (axp->proto == V1 || !axp->remotebusy)){
  128.         /* Retransmit oldest unacked I-frame */
  129.         dup_p(&bp,axp->txq,0,len_mbuf(axp->txq));
  130.         ctl = PF | I | ((axp->vs - axp->unack) & MMASK) << 1
  131.          | axp->vr << 5;
  132.         sendframe(axp,COMMAND,ctl,bp);
  133.     } else {
  134.         ctl = len_mbuf(axp->rxq) >= axp->window ? RNR|PF : RR|PF;    
  135.         sendctl(axp,COMMAND,ctl);
  136.     }
  137.     axp->response = 0;    
  138.     stop_timer(&axp->t3);
  139.     start_timer(&axp->t1);
  140. }
  141.  
  142.